import pytest
import logging
import requests
class TestWdmovie():
    ipaddr="http://10.59.9.18"
    uid=""
    sid=""
    movieid=""  #电影id
    cenimaid="" #电影院id
    oid="" #订单id

    def setup_method(self):
        pass
    def teardown_method(self):
        pass

    #用例--登录
    def test_login(self):
        url=TestWdmovie.ipaddr+"/movieApi/user/v2/login"
        data={"email":"1478997572@qq.com","pwd":"eWLPHopE945d2ivttHaQTQ=="}
        r = requests.post(url=url,params=data)
        print(r.json())
        TestWdmovie.uid=r.json()['result']['userId']
        TestWdmovie.sid=r.json()['result']['sessionId']
        # logging.debug("登录成功")
    #查询正在上映电影列表
    def test_findReleaseMovieList(self):
        url="http://10.59.9.18/movieApi/movie/v2/findReleaseMovieList"
        data={"page":"1","count":"10"}
        r = requests.get(url=url,params=data)
        print("\n电影列表：",r.json())
        assert "碟中谍6" in r.json()['result'][0]['name']
        TestWdmovie.movieid=r.json()['result'][0]['movieId']

   #查询附近影院

    def test_findNearbyCinemas(self):
        url = "http://10.59.9.18/movieApi/cinema/v1/findNearbyCinemas"
        data = {"longitude":"115","latitude":"34","page": "1", "count": "10"}
        # tou = {"userId":TestWdmovie.uid,"sessionId":TestWdmovie.sid}
        r = requests.get(url=url, params=data)
        TestWdmovie.cenimaid = r.json()['result'][0]['id']
        print("asdjkfjasdklfjadslkjfkldas")
        print("\n附件电影院列表",r.json())
        # logging.info("aaaaa")
        # assert "碟中谍6" in r.json()['result'][0]['name']

    # 根据电影ID和影院ID查询电影排期列表
    def test_findMovieSchedule(self):
        url = "http://10.59.9.18/movieApi/movie/v2/findMovieSchedule"
        data = {"movieId": TestWdmovie.movieid, "cinemaId": TestWdmovie.cenimaid}
        # tou = {"userId":TestWdmovie.uid,"sessionId":TestWdmovie.sid}
        r = requests.get(url=url, params=data)

        print("\n查询电影排期列表", r.json())
    #购票下单
    def test_buyMovieTickets(self):
        url = "http://10.59.9.18/movieApi/movie/v2/verify/buyMovieTickets"
        data = {"scheduleId":464,"seat":["1-1"],"sign":"26852c23ac31bacbc8754c629ccf20d8"}
        tou = {"userId":str(TestWdmovie.uid),"sessionId":TestWdmovie.sid}

        r = requests.post(url=url, json=data,headers=tou)
        # TestWdmovie.oid=r.json()['orderId']  #关联订单id，提取
        # print("aaaaaaaaaaaaaaaaaa",TestWdmovie.oid)
        print("\n购票下单", r.json())
    #支付
    def test_pay(self):
        url = "http://10.59.9.18/movieApi/movie/v2/verify/pay"
        data = {"payType":1,"orderId":TestWdmovie.oid}  #关联订单id
        tou = {"userId":str(TestWdmovie.uid),"sessionId":TestWdmovie.sid}

        r = requests.post(url=url, json=data,headers=tou)

        print("\n支付结果", r.json())

# def log_set():
#     logging.basicConfig(level=logging.DEBUG,format="%(thread)d-%(levelname)s",filename='log.txt',filemode='a+')
#
# if __name__ == '__main__':
#     log_set()